home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3MCp.sea Folder / Made by Marksman / Sources / mm / mmMD_My_Modeless.cp < prev    next >
Encoding:
Text File  |  1994-01-16  |  8.2 KB  |  249 lines  |  [TEXT/MMCC]

  1.  
  2. /*  mmMD_My_Modeless                                 Handle this dialog */
  3. /*  Copyright © 1994 George R. Cossey */
  4.  
  5. /*    File name:  mmMD_My_Modeless.c
  6.     Function:  Handle this modeless dialog.
  7.  
  8.     This dialog is called when:
  9.  
  10.     History: 1/16/94 Original by George Cossey
  11.  
  12. */
  13.  
  14. #include "mmCommonMM_Demo.h"    /* Common */
  15. #include "CommonMM_Demo.h"        /* Common */
  16.  
  17. /* ======================================================= */
  18. /* ======================================================= */
  19.  
  20. /* Routine: Init */
  21. /* Purpose: This procedures purpose is to set the window pointer to nil, */
  22. /* this is used to tell the other routines */
  23.  
  24. void CmmMDMy_Modeless::Init()
  25. {
  26.  
  27.  
  28. inherited::Init();
  29.  
  30. this->Enable_OK5 = true;            /* Button */
  31. this->Enable_Cancel4 = true;            /* Button */
  32. this->Enable_My_Scroll_bar = true;            /* ScrollBar */
  33. this->Value_My_Scroll_bar = 1;
  34. this->Enable_The_Icon = true;            /* Icon button */
  35. this->Enable_The_Sicn = true;            /* Sicn button */
  36. this->Enable_Tool_palette = true;            /* Palette */
  37. this->Value_Tool_palette = 0;
  38. }
  39.  
  40. /* ======================================================= */
  41.  
  42. /* Routine: Update */
  43. /* Purpose: This procedures purpose is to refresh this window, update it, */
  44. /* when we are uncovered by another window.  */
  45.  
  46. void CmmMDMy_Modeless::Update(WindowPtr theWindow)
  47. {
  48. GrafPtr    SavedPort;                                /* Save the current port so we can restore to it */
  49. Rect    tempRect;                                    /* Temporary rectangle variable */
  50. Rect    rTempRect;                                    /* Temporary rectangle variable */
  51. short    DType;                                    /* Type of dialog item */
  52. Handle    DItem;                                    /* Handle to the dialog item */
  53. ControlHandle    CItem;                            /* Control handle */
  54. RGBColor    Saved_ForeColor;                        /* Place to save colors */
  55. RGBColor    Saved_BackColor;                        /* Place to save colors */
  56. RGBColor    DrawingColor;                            /* Place to make colors */
  57.  
  58.  
  59. if ((this->theWindow != nil) && (theWindow == this->theWindow))/* Only do if we are the window to update */
  60.     {
  61.     GetPort(&SavedPort);                            /* Get the current port */
  62.     SetPort(theWindow);                            /* Point to our port for drawing in our window */
  63.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  64.         {
  65.         GetForeColor(&Saved_ForeColor);            /* Save the fore color */
  66.         GetBackColor(&Saved_BackColor);            /* Save the back color */
  67.  
  68.         RGBForeColor(&Black_ForeColor);            /* Set the fore color to Black */
  69.         RGBBackColor(&White_BackColor);            /* Set the back color to White */
  70.         }                                        /* End of IF */
  71.  
  72.     /* This is the default selection, when RETURN is pressed. */
  73.     HiliteDefaultButton(theWindow,ResD_OK5);
  74.  
  75.     /* Draw a line, Drawn line */
  76.     PenSize(1,1);
  77.     MoveTo(110,110);        /* Horz,vert, Move to starting position */
  78.     LineTo(284,110);    /* Horz,vert, Draw to the ending position */
  79.     PenSize(1,1);
  80.  
  81.     TextSize(12);
  82.     TextFont(systemFont);                                /* Select the Font that we want */
  83.     TextFace(0);                                        /* Select the style that we want */
  84.  
  85.     if (Has.ColorQD)                                    /* See if color QuickDraw is around */
  86.         {
  87.         RGBForeColor(&Saved_ForeColor);                    /* Restore the fore color */
  88.         RGBBackColor(&Saved_BackColor);                    /* Restore the back color */
  89.         }
  90.  
  91.  
  92.     this->UpdateExtras();                        /* HOOK, allow user update code */
  93.     
  94.     DrawDialog(theWindow);                        /* Draw the rest of the controls */
  95.     SetPort(SavedPort);                            /* Restore the port that we saved at the start */
  96.     }
  97. }
  98.  
  99. /* ======================================================= */
  100.  
  101. /* Routine: Open */
  102. /* Purpose: This procedures purpose is to open this window and set all */
  103. /* of the initial conditions, such as default edit text. */
  104.  
  105. void CmmMDMy_Modeless::Open()
  106. {
  107. Rect            tempRect;                            /* Temporary rectangle variable */
  108. short            DType;                                /* Type of dialog item */
  109. Handle            DItem;                                /* Handle to the dialog item */
  110. ControlHandle    CItem;                                /* Control handle */
  111. long            LTemp,LTemp2,theLong;                /* Get selection, temp holding */
  112. DialogPtr        theDialog;
  113.  
  114.  
  115. if (this->theWindow == NIL)
  116.     {
  117.     this->theWindow = GetNewDialog(ResD_My_Modeless,NIL,(WindowPtr)-1 );/* Bring in the dialog resource */
  118.     theDialog = this->theWindow;
  119.     SetPort(theDialog);                /* Prepare to add conditional text */
  120.  
  121.     /* Button */
  122.     SetupNormalControl(theDialog,ResD_OK5,this->Enable_OK5,0);
  123.  
  124.     /* Button */
  125.     SetupNormalControl(theDialog,ResD_Cancel4,this->Enable_Cancel4,0);
  126.  
  127.     /* Draw a Hotspot or Rectangle */
  128.     SetupHotSpot(theDialog,ResD_Message_on_rect,false,1,
  129.         1,sResD_Message_on_rect,this->Enable_Message_on_rect);
  130.  
  131.     /* Draw a Palette */
  132.     SetupPalette(theDialog,ResD_Tool_palette,this->Enable_Tool_palette,
  133.         3,3,ResD_N_Tool_palette,6);
  134.  
  135.     /* Draw an Icon button */
  136.     SetupIconSicn(theDialog,ResD_The_Icon,this->Enable_The_Icon,
  137.         ResD_N_The_Icon,ResD_H_The_Icon);
  138.  
  139.     /* Draw a Sicn */
  140.     SetupIconSicn(theDialog,ResD_The_Sicn,this->Enable_The_Sicn,
  141.         ResD_N_The_Sicn,ResD_H_The_Sicn);
  142.  
  143.     SetupTheItem(theDialog,ResD_My_Scroll_bar,true,true,this->Enable_My_Scroll_bar,true,&tempRect,0,0);
  144.     SetupMinMaxValue(theDialog,ResD_My_Scroll_bar,1,100,this->Value_My_Scroll_bar);
  145.  
  146.  
  147.  
  148.     this->OpenExtras();                    /* Call the user Open procedure */
  149.  
  150.     ShowWindow(theDialog);                /* Open a dialog box */
  151.     SelectWindow(theDialog);            /* Lets see it */
  152.     }
  153. else
  154.     SelectWindow(this->theWindow);        /* Lets see it */
  155. }
  156.  
  157. /* ======================================================= */
  158.  
  159. /* Routine: Close_My_Modeless */
  160. /* Purpose: This procedures purpose is to close this window and clear */
  161. /* the window pointer variable */
  162.  
  163. void CmmMDMy_Modeless::Close(WindowPtr theWindow)
  164. {
  165. Rect    tempRect;                                    /* Temporary rectangle */
  166. short    DType;                                        /* Type of dialog item */
  167. Handle    DItem;                                        /* Handle to the dialog item */
  168.  
  169.  
  170. if ((this->theWindow != NIL) && (theWindow == this->theWindow))/* Only close if it is us and we were open */
  171.     {
  172.  
  173.     DisposDialog(theWindow);                        /* Close on the screen and Flush the dialog out of memory */
  174.     this->theWindow = nil;                            /* Make sure our other routines know that we are closed */
  175.     }
  176. }
  177.  
  178. /* ======================================================= */
  179.  
  180. /* Routine: HandleEvent */
  181. /* Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. */
  182. /* This is the real meat of this unit and is where the code is for acting upon the users actions. */
  183.  
  184. void CmmMDMy_Modeless::HandleEvent(EventRecord *theEvent,WindowPtr theWindow,short itemHit)
  185. {
  186. short    Index;                                        /* For looping */
  187. Point    myPt;                                        /* For the local mouse position */
  188. short    DType;                                        /* Type of dialog item */
  189. Handle    DItem;                                        /* Handle to the dialog item */
  190. Rect    tempRect;                                    /* Temporary rectangle */
  191. ControlHandle    CItem;                                /* Control handle */
  192. short    temp;                                        /* temp integer */
  193. short    code;                                        /* temp integer */
  194. short    theSelection;                                /* For Palettes */
  195. Boolean    DoubleClick;                                /* For sensing double clicks in a list */
  196. DialogPtr        theDialog;
  197.  
  198.  
  199. this->ExitDialog = false;                    /* Do not close the dialog yet */
  200. if ((theEvent->what == mouseDown) && (this->theWindow != nil))
  201.     {
  202.     SetPort(this->theWindow);                    /* Set the port to our dialog */
  203.     myPt = theEvent->where;                            /* Get the position where the mouse was pressed */
  204.     GlobalToLocal(&myPt);                            /* Change from global to local location */
  205.  
  206.     }
  207.  
  208. if ((this->theWindow != nil)  && (this->theWindow  == theWindow))
  209.     {
  210.     theDialog = this->theWindow;
  211.     
  212.     CheckKeysInDialog(theDialog,&DoubleClick,theEvent,&itemHit);
  213.  
  214.     myPt = theEvent->where;                            /* Get the position where the mouse was pressed */
  215.     GlobalToLocal(&myPt);                            /* Change from global to local location */
  216.  
  217.     this->FilterTheHit(&itemHit,theEvent);            /* Give the user the itemhit */
  218.  
  219.     if (itemHit > 0)                                /* Skip if user set to zero */
  220.         {
  221.         GetDItem(theDialog,itemHit,&DType,&DItem,&tempRect);/* Get which item was pressed */
  222.         CItem = (ControlHandle)DItem;                /* Change the pointer for getting to the control */
  223.         }
  224.     
  225.     /* Handle it real time */
  226.     if (itemHit == ResD_OK5)                /* Handle the Button being pressed */
  227.         {
  228.         Add_UserEvent(UserEvent_Close_Window,ResD_My_Modeless,0,0,nil);    /* Close this modeless dialog */
  229.         this->ExitDialog = true;                    /* Close this dialog, exit */
  230.         }
  231.  
  232.     if (itemHit == ResD_Cancel4)                /* Handle the Button being pressed */
  233.         {
  234.         Add_UserEvent(UserEvent_Close_Window,ResD_My_Modeless,0,0,nil);    /* Close this modeless dialog */
  235.         this->ExitDialog = true;                    /* Close this dialog, exit */
  236.         }
  237.  
  238.     /* Palette */
  239.  
  240.  
  241.     }
  242.  
  243. if (this->ExitDialog)                        /* Do the close of the dialog */
  244.     this->Close(this->theWindow);
  245. }
  246.  
  247. /* ======================================================= */
  248. /* ======================================================= */
  249.